import threading
import time


# 唱歌函数
def sing():
    for i in range(5):
        print('正在唱歌...',i)
        time.sleep(0.5)


# 跳舞函数
def dance():
    for i in range(5):
        print("正在跳舞....",i)
        time.sleep(0.5)


# 调用
if __name__ == '__main__':
    # 线程的名称  threading.current_thread() 获取当前线程对象
    print(threading.current_thread())

    # threading.enumerate() 可以获取正在获取的线程列表
    thread_list = threading.enumerate()
    print("1.当前线程数量：",len(thread_list))

    # 1.导入模块
    # 2.创建线程对象
    thread_sing = threading.Thread(target=sing)
    thread_dance = threading.Thread(target=dance)

    # 3.启动子线程
    thread_sing.start()
    thread_dance.start()


    while True:
        thread_num = len(threading.enumerate())
        print("3当前线程数量：",thread_num)

        # 如果只剩下主线程就会停止
        if thread_num <=1:
            break
        time.sleep(0.5)

